﻿using FreeSql;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EONFULLSIN.Utils
{
    public class DBHelper
    {
        static DBHelper()
        {
            string dbFileName = AppDomain.CurrentDomain.BaseDirectory + "Common\\DataBase\\EonFulldb.db";
            if (!File.Exists(dbFileName))
            {
                LoggerHelper.Logger.Error("create db file");
                File.Create(dbFileName);
            }
            DbContext = new FreeSqlBuilder()
                            .UseConnectionString(DataType.Sqlite, $"Data Source={dbFileName}")
                            .UseAutoSyncStructure(true)
                            .Build();

            string historyFileName = AppDomain.CurrentDomain.BaseDirectory + "Common\\DataBase\\EonFullHistory.db";
            if (!File.Exists(historyFileName))
            {
                LoggerHelper.Logger.Error("create history db file");
                File.Create(historyFileName);
            }

            HistoryDbContext = new FreeSqlBuilder()
                            .UseConnectionString(DataType.Sqlite, $"Data Source={historyFileName}")
                            .UseAutoSyncStructure(true)
                            .Build();
        }

        public static readonly IFreeSql DbContext;

        public static readonly IFreeSql HistoryDbContext;
    }
}